//
//  HESettingViewController.m
//  huien
//
//  Created by yiban on 2017/5/27.
//  Copyright © 2017年 lcb. All rights reserved.
//

#import "HESettingViewController.h"
#import "Html5ViewController.h"
@interface HESettingViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    
}
@property(nonatomic,strong)LcbUITableView *lcbTableView;
@property(nonatomic,strong)NSMutableArray *menuArray;

@end

@implementation HESettingViewController
@synthesize lcbTableView=_lcbTableView;
@synthesize menuArray=_menuArray;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navTitle = @"系统管理";
    if (!_menuArray) {
        _menuArray =[[NSMutableArray alloc] init];
    }
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *appCurVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    NSString *version =[NSString stringWithFormat:@"当前版本:   %@",appCurVersion];
    _menuArray = [NSMutableArray arrayWithObjects:@"公告",@"关于惠恩资本",@"联系我们",@"客服",version, nil];
    [self initTableView];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)dealloc
{
    if (_lcbTableView) {
        [_lcbTableView removeFromSuperview];
        _lcbTableView=nil;
    }
    [LcbLog log:@"HESettingViewController--------->dealloc"];
}
#pragma mark - tableview delegate
-(void)initTableView
{
    //
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 20, 60, 44);
    backButton.tag =100;
    [backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    backButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [backButton addTarget:self action:@selector(clickNavEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.headerView addSubview:backButton];
    //
    if (_lcbTableView) {
        [_lcbTableView removeFromSuperview];
        _lcbTableView=nil;
    }
    _lcbTableView =[[LcbUITableView alloc] initWithFrame:CGRectMake(0, YB_HeaderHeight, SCREEN_WIDTH, SCREEN_HEIGHT-YB_HeaderHeight) style:UITableViewStyleGrouped];
    _lcbTableView.dataSource=self;
    _lcbTableView.delegate=self;
    _lcbTableView.backgroundColor=[UIColor clearColor];
//    _lcbTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_lcbTableView];
}
-(void)clickNavEvent:(id)sender
{
    if (self.navigationController) {
        if (self.navigationController.viewControllers.count == 1) {
            [self.navigationController dismissViewControllerAnimated:YES completion:nil];
        } else {
            [self.navigationController popViewControllerAnimated:YES];
        }
    } else {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    
}
//
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.menuArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return LcbHEIGHT(40);
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell  *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (cell == nil) {
        cell = [[UITableViewCell  alloc]initWithStyle:UITableViewCellStyleDefault   reuseIdentifier:@"UITableViewCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone; 
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        UIView *line =[[UIView alloc] initWithFrame:CGRectMake(10, LcbHEIGHT(40)-1, SCREEN_WIDTH-10, 1)];
        line.backgroundColor=linecolor;
        [cell.contentView addSubview:line];
        line=nil;
    }
    NSString *celltitle = [self.menuArray objectAtIndex:indexPath.row];
    cell.textLabel.text=celltitle;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *celltitle = [self.menuArray objectAtIndex:indexPath.row];
    if ([celltitle isEqualToString:@"公告"]) {
        ModuleModel *moudulModel = [[ModuleModel alloc] init];
        moudulModel.action =@"/mobileMoreIntroduc/notices";
        moudulModel.title =@"公告列表";
        moudulModel.method =@"GET";
        
        [[NativeRouter sharedNativeRouter] nativeRouter:self params:moudulModel completion:^(id obj) {
            
        }];
        return;
    }else if ([celltitle isEqualToString:@"关于惠恩资本"]) {
        ModuleModel *moudulModel = [[ModuleModel alloc] init];
        moudulModel.action =@"/mobileMoreIntroduc/about";
        moudulModel.title =@"关于惠恩资本";
        moudulModel.method =@"GET";
        
        [[NativeRouter sharedNativeRouter] nativeRouter:self params:moudulModel completion:^(id obj) {
            
        }];
        return;
    }else if ([celltitle isEqualToString:@"联系我们"]) {
        ModuleModel *moudulModel = [[ModuleModel alloc] init];
        moudulModel.action =@"/mobileMoreIntroduc/contact";
        moudulModel.title =@"联系我们";
        moudulModel.method =@"GET";
        
        [[NativeRouter sharedNativeRouter] nativeRouter:self params:moudulModel completion:^(id obj) {
            
        }];
        return;
    }else if ([celltitle isEqualToString:@"客服"]) {
        return [LcbSystem phone:@"400-662-1617"];
    }else if ([celltitle isEqualToString:@"给我们评分"]) {
        return [LcbSystem brower:@"https://itunes.apple.com/us/app/惠恩资本/id1090615448?l=zh&ls=1&mt=8"];
    }
}
@end
